-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform provider ProfitBricks - Data Sources #11520
Terraform provider ProfitBricks - Data Sources #11520
Conversation
…r-profitbricks # Conflicts: # command/internal_plugin_list.go
- nat parameter for Nics - availabilityZone for Volumes Minor code clean up
I'm using this PR to update to ProfitBicks REST V3. Adding following parameters:
|
👀 are on this now @jasminSPC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jasminSPC
So the new data sources look good - I am not quite sure what we can do about the dangling resources
If this is an error on the profitbricks side, then we may need to have a step n the CheckDestroy that cleans everything up for us. Alternatively, we can have a script that runs after the tests that cleans up any dangling resources - the maintainer of the scaleway provider did the same thing here
With regards to that unit test - let's not worry too much about that right now - I will dig into that soon and have a look at what is going on there
P.
return fmt.Errorf("An error occured while fetching datacenters %s", datacenters.Response) | ||
} | ||
|
||
name, _ := d.GetOk("name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as it's a required field we can guarantee it's there so we can write
name := d.Get("name").(string)
"testing" | ||
) | ||
|
||
func TestAccDataSourceDatacenter_basic(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a test that matches a datacenter name here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is tricky in order to get a match we need to have a data center. I'm not sure how to accomplish that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the test, have 2 steps, the first as a setup to create the datacenter, then the second will include a datacenter and a lookup
have a look at this test as an example https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/data_source_aws_autoscaling_groups_test.go#L15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried something similar:
In first step I do this:
resource "profitbricks_datacenter" "foobar" {
name = "datacenter-test"
location = "us/las"
}
and then this.
resource "profitbricks_datacenter" "foobar" {
name = "datacenter-test-updated"
location = "us/las"
}
data "profitbricks_datacenter" "data_source"{
name = "datacenter-test-updated"
location= "us/las"
}
Each time I do this it simply doesn't work.
How do you want me to proceed?
return fmt.Errorf("An error occured while fetching ProfitBricks locations %s", images.Response) | ||
} | ||
|
||
name, _ := d.GetOk("name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name isn't required, so we should check it's ok before using it
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"id": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually don't need to expose Id as a param - it's there by default
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"id": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually don't need to expose Id as a param - it's there by default
return fmt.Errorf("There are no images that match the search criteria") | ||
} | ||
|
||
d.Set("name", results[0].Properties.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check that Properties != nil ? Otherwise we could panic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties ImageProperties `json:"properties,omitempty"
It can't be nil it is not a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 sorry - still in AWS land where everything is a pointer :)
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"id": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually don't need to expose Id as a param - it's there by default
The loadbalancer thing is a known issue with ProfitBricks and we can't do much about that. |
…ng sure that the test doesn't leave dangling resources in ProfitBricks
Hey so i just went through this and it looks good - I ran the tests and got 1 error
I think we are going to have an issue with that test if it revs a version each month though so all in all this is looking good P. |
The problem with the test is that ProfitBricks is changing image names on monthly basis. |
Code clean up
This LGTM! :)
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
While this PR is fresh I have two issues with unit tests:
resource_profitbricks_loadbalancer_test - The issue is within ProfitBricks API. When a load balancer is provisioned it creates a private LAN and attaches it to existing NIC. This is leaving .tfstate with "dangling resources". This is a known issue with ProfitBricks
resource_profitbricks_volume_test - The script used for unit tests is working when ran separately but once unit tests run I get this error:
I'm not sure how to fix this.
@stack72 do you have any ideas?